package com.erp.Util;


import com.erp.comm.TreeNode;

import java.util.ArrayList;
import java.util.List;



//节点层级关系构建
public class TreeNodeBuilder {

    public static List<TreeNode> Builder(List<TreeNode> nodes,Integer topId) {

        List<TreeNode> list = new ArrayList<TreeNode>();
        for (TreeNode node1 : nodes) {
            if (node1.getPid() == topId) {
                list.add(node1);
            }
            for (TreeNode node2 : nodes) {
                if (node1.getId() == node2.getPid()) {
                    node1.getChildren().add(node2);
                }
            }

        }
        return list;
    }




}
